<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    <script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <title>推荐会员</title>
</head>
<body style="color: #00aaaa">
<div class="container">
    <center><h2>推荐新会员</h2></center>
    <form action="{:U('Member/member_add')}" method="post">
        <div class="form-group">
            <label for="name">姓名</label>
            <input type="text" class="form-control" id="name" placeholder="请输入姓名" name="name">
        </div>
        <div class="form-group">
            <label for="tel">电话</label>
            <input type="text" class="form-control" id="tel" placeholder="请输入电话" name="tel">
        </div>
        <div class="form-group">
            <label for="sex">性别</label>
            <select class="form-control" id="sex" name="sex">
                <option value="1">男</option>
                <option value="2">女</option>
            </select>
        </div>
        <div class="form-group">
            <label>省份</label>
            <select name="user_add_1" id="J_province" class="form-control"></select>
        </div>
        <div class="form-group">
            <label>城市</label>
            <select name="user_add_2" id="J_city" class="form-control"></select>
        </div>
        <div class="form-group">
            <label>区/县</label>
            <select name="user_add_3" id="J_district" class="form-control"></select>
        </div>
        <div class="form-group">
            <label for="tel">详细地址</label>
            <input type="text" class="form-control"  placeholder="请输入街道门牌号" name="add_4">
            <input name="area_id" type="hidden" id="area_id"/>
        </div>
    </form>
    <div class="alert alert-danger" role="alert" id="warning" style="display: none"></div>
    <button class="btn btn-info btn-block" type="submit" id="submit" onclick='sub();'>提交</button>
</div>
<script type="text/javascript">
    /**警告**/
    function warning(info){
        $('#warning').text(info).show('slow',function(){
            setTimeout(function () {
                $('#warning').hide('1000');
            },2000);
        });
    }
    function sub() 
    {
        var obj = $('form').serializeArray();
        $.post("{:U('Member/member_add')}",obj,function (data){
            if (data.reg == 1) {
                alert('推荐会员成功!');
                WeixinJSBridge.call('closeWindow');
            } else {
                warning(data.info);
            }
        });
    }
    $('#J_district').change(function(){
        var did_g = $(this).children('option:selected').attr('data');
        $('#area_id').val(did_g);
    });

    $(function(){

        var pid=<if condition="$param.province neq ''">{$param.province}<else />0</if>;  //默认省份id
        var cid=<if condition="$param.city neq ''">{$param.city}<else />0</if>;  //默认城市id
        var did=<if condition="$param.district neq ''">{$param.district}<else />0</if>;  //默认区县市id
        var coid=<if condition="$param.community neq ''">{$param.community}<else />0</if>;  //默认乡镇id


        $.post("{:addons_url('ChinaCity://ChinaCity/getProvince')}", {pid: pid}, function(result){
            $("#J_province").html(result);
        });

        $.post('{:addons_url("ChinaCity://ChinaCity/getCity")}', {pid: pid, cid: cid}, function(result){
            $("#J_city").show().html(result);
        });

        $.post('{:addons_url("ChinaCity://ChinaCity/getDistrict")}', {cid: cid, did: did}, function(result){
            $("#J_district").show().html(result);
        });

        $.post('{:addons_url("ChinaCity://ChinaCity/getCommunity")}', {did: did, coid: coid}, function(result){
            $("#J_community").show().html(result);
        });

        $('#J_province').change(function(){
            var pid_g=$(this).children('option:selected').attr('data');
            $.post('{:addons_url("ChinaCity://ChinaCity/getCity")}', {pid: pid_g}, function(result){
                //console.log(result);
                $("#J_city").show().html(result);
            });
        });

        $('#J_city').change(function(){
            var cid_g=$(this).children('option:selected').attr('data');
            $.post('{:addons_url("ChinaCity://ChinaCity/getDistrict")}', {cid: cid_g}, function(result){
                $("#J_district").show().html(result);
            });
        });

//	$('#J_district').change(function(){
//		var did_g=$(this).children('option:selected').attr('data');
//		$.post('{:addons_url("ChinaCity://ChinaCity/getCommunity")}', {did: did_g}, function(result){
//			$("#J_community").show().html(result);
//		});
//	});

    });
</script>
</body>
</html>